<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="com.lmpop.trade.ti_orderinfo.Ti_orderinfoInfo" %>
<%@ page import="com.lmpop.frame.util.PageTools" %>
<%@ page import="com.lmpop.trade.tb_ordergoods.Tb_ordergoodsInfo" %>
<%@ page import="com.lmpop.trade.tb_commpara.Tb_commparaInfo" %>
<%@ page import="com.lmpop.frame.util.Config" %>
<%@ page import="com.lmpop.trade.ti_evaluate.Ti_evaluateInfo" %>
<%@ page import="com.lmpop.trade.ts_categoryattr.Ts_categoryattrInfo" %>
<%@ page import="com.lmpop.createIndex.search.*"%>
<%@page import="com.lmpop.trade.ti_company.*" %>

<%

  GoodsIndexFiles goodsIndex = new GoodsIndexFiles();
	request.setCharacterEncoding("UTF-8");
	Ti_orderinfoInfo ti_orderinfoInfo = new Ti_orderinfoInfo();
	Tb_commparaInfo commparaInfo = new Tb_commparaInfo();
	Map params = new Hashtable();
	Ti_companyInfo ti_companyInfo = new Ti_companyInfo();
  
  String custrootpath = "/data/company/";
  
  String s_order_no="",o_start_date="",o_end_date="",o_order_state="";
  if(request.getParameter("s_order_no")!=null && !request.getParameter("s_order_no").equals(""))
  {
      s_order_no = request.getParameter("s_order_no"); 
      params.put("order_no",s_order_no);
  }
  if(request.getParameter("o_start_date")!=null && !request.getParameter("o_start_date").equals(""))
  {
      o_start_date = request.getParameter("o_start_date"); 
      params.put("start_date",o_start_date); 
  }
  if(request.getParameter("o_end_date")!=null && !request.getParameter("o_end_date").equals(""))
  {
      o_end_date = request.getParameter("o_end_date"); 
      params.put("end_date",o_end_date); 
  }
  if(request.getParameter("o_order_state")!=null && !request.getParameter("o_order_state").equals(""))
  {
      o_order_state = request.getParameter("o_order_state"); 
      params.put("order_state",o_order_state); 
  }

	params.put("user_id",_user_id);
 	

 	String iStart = "0";

	int limit = 5;
	if(request.getParameter("iStart")!=null) iStart = request.getParameter("iStart");

	List list = ti_orderinfoInfo.getPersonalListByPage(params,Integer.parseInt(iStart),limit);
	int counter = ti_orderinfoInfo.getPersonalCountByObj(params);

	String pageString = new PageTools().getGoogleToolsBar(counter,"index.jsp?o_order_state="+o_order_state+"&o_end_date="+o_end_date+"&o_start_date="+o_start_date+"&s_order_no="+s_order_no+"&menu_id="+menu_id+"&iStart=",Integer.parseInt(iStart),limit);

	Tb_ordergoodsInfo  tb_ordergoodsInfo  = new Tb_ordergoodsInfo();


	String orderStateSelect = commparaInfo.getSelectItem("31",o_order_state);
	Config configa = new Config();
	String goods_article_path = configa.getString("goods_article_path");
	String company_shop_path = configa.getString("company_shop_path");

	Ti_evaluateInfo evaluateInfo = new Ti_evaluateInfo();
	Ts_categoryattrInfo catAttrInfo = new Ts_categoryattrInfo();
%>

<div class="f-right">
	<script type="text/javascript" src="/js/jquery.js"></script>
<script src="js_order.js"></script>
 <script language="javascript" type="text/javascript" src="/program/plugins/calendar/WdatePicker.js"></script>
	<form action="index.jsp" name="orderForm" method="post">

    <table width="100%" border="0" cellspacing="0" cellpadding="0">

      <tr>

        <td><table width="100%" border="0" cellpadding="0" cellspacing="0" class="table_main" >

            <tr>

              <th width="5%" height="40" align="center"><img src="/program/member/index/images/icon1.gif" ></th>

              <th width="85%"><h3>我的订单</h3></th>

			  <th width="10%"> </th>

            </tr>

          </table>

		     <table width="100%" border="0" cellspacing="0" cellpadding="0" class="ts">
            <tr>
              <td height="42" align="left">
              	  订单编号:
                  <input type="text" class="input" name ="s_order_no" id= "s_order_no" maxlength="50">
                  下单时间:  
				          <input name="o_start_date" type="text" id="o_start_date" class="Wdate" value="" onclick="WdatePicker({maxDate:'#F{$dp.$D(\'o_end_date\',{d:-1})}',readOnly:true})" size="15"  width="150px"/>
				            -
					        <input name="o_end_date" id="o_end_date" type="text" class="Wdate" value="" onclick="WdatePicker({minDate:'#F{$dp.$D(\'o_start_date\',{d:1})}',readOnly:true})" size="15" width="150px"/>
						              
				          
                  <input type="button" name="Submit" value="搜索" onclick="document.orderForm.submit();" class="button2">

              </td>
            </tr>
          </table>

      <table width="100%" cellspacing="1" cellpadding="1" class="table_ls" >
			<tr height="30">
				<th width="280" align="center" >商品名称</th>  	
				<th width="80" align="center">单价(元)</th>
				<th width="50" align="center">数量</th>
				<th width="100" align="center">实付款(元)</th>
				<th width="150" align="center">
					<select id="o_order_state" name="o_order_state" onchange="document.orderForm.submit();">
					  <option value="">交易状态</option> 
					  <%=orderStateSelect%> 
				   </select>
				</th>
				<th width="70" align="center">操作</th>
            </tr>
       </table>

          <% 

          int listsize = 0;
		  List goodslist = new ArrayList();

				 if(list!=null && list.size()>0){

					Hashtable map = new Hashtable();
					Hashtable gmap = new Hashtable();
					listsize = list.size();
					for(int i=0;i<list.size();i++){

					  map = (Hashtable)list.get(i);

					  String order_no="",order_source="",order_state="",all_goods_amount="",shipping_name="",peisong_no="",peisong_company="";
		  			  String all_shipping_fee="",all_pack_fee="",all_tax_invoice="",all_total_amount="",all_user_money="";
		  			  String all_integral_money="",all_discount="",all_confirm_money="",all_paid_amount="",add_time="",shop_name="",cust_id="";
		  			  String pay_id="";
					  if(map.get("order_no")!=null) order_no = map.get("order_no").toString();
					  if(map.get("all_goods_amount")!=null) all_goods_amount = map.get("all_goods_amount").toString();
					  if(map.get("all_total_amount")!=null) all_total_amount = map.get("all_total_amount").toString();
					  if(map.get("all_shipping_fee")!=null) all_shipping_fee = map.get("all_shipping_fee").toString();
					  if(map.get("all_pack_fee")!=null) all_pack_fee = map.get("all_pack_fee").toString();
					  if(map.get("all_tax_invoice")!=null) all_tax_invoice = map.get("all_tax_invoice").toString();
					  if(map.get("all_paid_amount")!=null) all_paid_amount = map.get("all_paid_amount").toString();
					  if(map.get("add_time")!=null) add_time = map.get("add_time").toString();
					  if(map.get("order_state")!=null) order_state = map.get("order_state").toString();
					  //if(map.get("shop_name")!=null) shop_name = map.get("shop_name").toString();
					  if(map.get("cust_id")!=null) cust_id = map.get("cust_id").toString();
					  if(map.get("pay_id")!=null) pay_id = map.get("pay_id").toString();
					  if(map.get("shipping_name")!=null) shipping_name = map.get("shipping_name").toString();
					  if(map.get("peisong_no")!=null) peisong_no = map.get("peisong_no").toString();
					  if(map.get("peisong_company")!=null) peisong_company = map.get("peisong_company").toString();
					  if(add_time.length()>19)add_time=add_time.substring(0,19);
			
					  String state_name = commparaInfo.getOneComparaPcode1("31",order_state);
					  
					  goodslist = tb_ordergoodsInfo.getPersonalOrderDetail(order_no);
					  String shipping_fee = all_shipping_fee;
//out.println("all_goods_amount="+(Double.valueOf(all_goods_amount)+Double.valueOf(all_pack_fee))+"=shipping_name="+shipping_name+"");
					  if(!all_pack_fee.equals("0.00")){
						 all_pack_fee = "(含包装费："+all_pack_fee + ")<br/>";
					  }else{all_pack_fee="";}
					  if(!all_tax_invoice.equals("0.00")){
						 all_tax_invoice = "(含税额："+all_tax_invoice + ")<br/>";
					  }else{all_tax_invoice="";}
					  if(!all_shipping_fee.equals("0.00")){
						 all_shipping_fee = "(含运费："+all_shipping_fee + ")<br/>";
					  }else{all_shipping_fee="";}

					  String custUrl = company_shop_path + cust_id;

					  boolean isNotEvaluate = evaluateInfo.checkIsnotEvaluate(order_no);
					  
					  /**获取商铺名称**/
					 
				  	List custlist = ti_companyInfo.getListByPk(cust_id);
				  	Hashtable custmap = new Hashtable();
				  	if(custlist!=null && custlist.size()>0)
				  	{
				  	 	custmap = (Hashtable)custlist.get(0);		  	 
				  		 
				  		if(custmap.get("short_name")!=null){shop_name = custmap.get("short_name").toString();} else {shop_name = custmap.get("cust_name").toString();}
				  	}
				  	if (cust_id.equals("100000000000000"))
				  	{
				  		custUrl = "/data/shop.html";
				  		shop_name = "自营";
				  	}

      
		  %>
          <table width="100%" style="border:1px solid #E6E6E6;"  cellpadding="1" cellspacing="1" style=" border:1px solid #EDDFEA;">
			<tr>
				<td height="30" colspan="7" style="background:#EBEBEB;">	   
					订单编号:<%=order_no%>
					&nbsp;
					下单时间: <span style="color:#666666;"><%=add_time%></span>
				     
				</td>
			</tr>


			<tr>
				<td width="410" colspan="3">
					<table width="100%"  cellpadding="0" border="0" cellspacing="0">
						<%
							if(goodslist!=null && goodslist.size()>0){
								Hashtable gMap = new Hashtable();
								for(int k=0;k<goodslist.size();k++){
									gMap = (Hashtable)goodslist.get(k);
									//out.print(gMap);
									String goods_id="",goods_name="",goods_attr="",goods_num="",shop_price="",total_price="",file_path="",in_date="",sale_cust_id="";
									if(gMap.get("goods_id")!=null) goods_id = gMap.get("goods_id").toString();
									Map ginfoMap = goodsIndex.getOneGoods(goods_id);
									if (ginfoMap.get("cust_id") != null && !ginfoMap.get("cust_id").toString().equals("")) sale_cust_id = ginfoMap.get("cust_id").toString();
									if(gMap.get("goods_name")!=null) goods_name = gMap.get("goods_name").toString();
									if(gMap.get("goods_attr")!=null) goods_attr = gMap.get("goods_attr").toString();
									if(gMap.get("goods_num")!=null) goods_num = gMap.get("goods_num").toString();
									if(gMap.get("shop_price")!=null) shop_price = gMap.get("shop_price").toString();
									if(gMap.get("total_price")!=null) total_price = gMap.get("total_price").toString();
									if(gMap.get("file_path")!=null) file_path = gMap.get("file_path").toString();
									if(gMap.get("in_date")!=null) in_date = gMap.get("in_date").toString();
									if(in_date.length()>10)in_date=in_date.substring(0,10);
									
									String infoUrl = "";
									 
									infoUrl = goods_article_path+in_date+"/"+goods_id+".html";
									 
									if(file_path.equals(""))
									{
										file_path ="/program/admin/images/cpwu.gif";            
									}

									String goods_attr_dis = catAttrInfo.getCatAttrFromStr(goods_attr,6);  
						%>

							<tr height="80">
								<td style="width:52px;">
									<a href="<%=infoUrl%>" target="_blank"><img src="<%=file_path%>" border="0" width="50" height="50" style="border:1px solid #cecece;
									margin-left:5px;"/></a>
								</td>
								<td valign="top" style="padding-top:10px;width:268px; text-align:left;"  class="goods_name"> 
									&nbsp;<a href="<%=infoUrl%>" target="_blank"><font class="goods_name<%=i%>"><%=goods_name%></font></a>
									<%
									
										if(order_state.equals("3")&&cust_id.equals("100000000000000") ){	
									%>
									&nbsp;<a href="returnIndex.jsp?return_state=3&order_no=<%=order_no%>&cust_id=<%=cust_id%>&goods_id=<%=goods_id%>&total_price=<%=total_price %>&goods_name=<%=java.net.URLEncoder.encode(goods_name,"UTF-8") %>">
									  <div style="background:url(/program/member/index/images/orderbg.jpg) repeat-x;width:57px;height:20px;line-height:20px;color:#fff;cursor:pointer;text-align:center;margin-left:3px;">退货</div>
									</a>
									<%}%>
									<%
										if(order_state.equals("5")&&cust_id.equals("100000000000000")){	
									%>
									 &nbsp;<a href="returnIndex.jsp?order_no=<%=order_no%>&cust_id=<%=cust_id%>&goods_id=<%=goods_id%>&total_price=<%=total_price %>&goods_name=<%=java.net.URLEncoder.encode(goods_name,"UTF-8") %>">[退货详细]</a>
									<%}%>
									
									<%
										if(order_state.equals("1") ){	
									%>
									&nbsp;<a href="returnIndex.jsp?return_state=1&order_no=<%=order_no%>&cust_id=<%=cust_id%>&goods_id=<%=goods_id%>&total_price=<%=total_price %>&goods_name=<%=java.net.URLEncoder.encode(goods_name,"UTF-8") %>">
									  <div style="background:url(/program/member/index/images/orderbg.jpg) repeat-x;width:57px;height:20px;line-height:20px;color:#fff;cursor:pointer;text-align:center;margin-left:3px;">退款</div>
									</a>
									<%}%>
									
									<br/>

									<%=goods_attr_dis%>
								</td>
								<td align="left" style="width:60px;"><%=shop_price%></td>
								<td align="center"><%=goods_num%></td>
							</tr>

						<%
								}
							}
						%>
						

					</table>
				</td>
				<td width="120" align="center" >
					<%=all_total_amount%><br/>
					<font color="#666666"><%=all_tax_invoice%><%=all_shipping_fee%><%=all_pack_fee%></font>
				</td>
				<td width="150" align="center">
					<%=state_name%><br/>
					<%
						if (order_state.equals("2"))
						{
					%>
					<p style="text-align:left;color:green">配送公司：<%=peisong_company%><br>单号：<%=peisong_no %></p>
					<%
						}
					%>
					<p><a href="detailindex.jsp?order_no=<%=order_no%>&menu_id=<%=menu_id%>" title="查看订单详细"><font color="#BB8600">订单详情</font></a></P>
				</td>
				<td width="70" align="center">
					<%
						if(order_state.equals("0")){
					%>

					<%
					if (!pay_id.equals("0")){ if (cust_id.equals("100000000000000")){
					%>
						
						<a href="javascript:pay('<%=order_no%>','<%=all_total_amount%>','<%=shipping_fee%>','<%=shipping_name%>','<%=i%>','<%=cust_id%>');" >
							<div style="background:url(/program/member/index/images/orderbg.jpg) repeat-x;width:80px;height:20px;line-height:20px;color:#fff;cursor:pointer;text-align:center;">付款</div>
						</a>						
					<%
					}else{
						%>
						<a href="javascript:paydb('<%=order_no%>','<%=all_total_amount%>','<%=shipping_fee%>','<%=shipping_name%>','<%=i%>','<%=cust_id%>');" >
							<div style="background:url(/program/member/index/images/orderbg.jpg) repeat-x;width:80px;height:20px;line-height:20px;color:#fff;cursor:pointer;text-align:center;">支付宝付款</div>
						</a>	
						<%
						}}
						 else{
					%>	
						货到付款
					<%
							}
						}
					%>					
					<%
						if(order_state.equals("2") && !cust_id.equals("100000000000000")){
					%>
						<!--a href="/doTradeReg.do?order_no=<%=order_no%>&order_state=3&bpm_id=5590"-->
						<a href="http://www.alipay.com" target="_blank">
						<div style="background:url(/program/member/index/images/orderbg.jpg) repeat-x;width:80px;height:20px;line-height:20px;color:#fff;cursor:pointer;text-align:center;">支付宝收货</div>
						</a>
					<%
					}else if (order_state.equals("2") && cust_id.equals("100000000000000")){
					%>					  
					  <a href="/doTradeReg.do?order_no=<%=order_no%>&order_state=3&bpm_id=5590">						 
						<div style="background:url(/program/member/index/images/orderbg.jpg) repeat-x;width:80px;height:20px;line-height:20px;color:#fff;cursor:pointer;text-align:center;">确认收货</div>
						</a>
					<%
					}
					%>
					<%
						if(order_state.equals("3") && isNotEvaluate){
					%>
						<a href="/program/member/memberevaluate/commentIndex.jsp?order_no=<%=order_no%>&cust_id=<%=cust_id%>&menu_id=4865kY45B7388tV">
						<div style="background:url(/program/member/index/images/orderbg.jpg) repeat-x;width:80px;height:20px;line-height:20px;color:#fff;cursor:pointer;text-align:center;">评价</div>
						</a>
					<%
						}
					%>
					<%
						if(!isNotEvaluate){
					%>
						<font color="#808080">已评价</font><br/>
						<a href="/program/member/memberevaluate/viewcommentindex.jsp?menu_id=4865kY45B7388tV&order_no=<%=order_no%>#seeDetail"><font color="#BB8600">评价详细</font></a>
					<%
						}
					%>
					
					
					
				</td>
			</tr>


          </table>

          <%

          		}

          	}

          %>

          <table width="100%" border="0" cellpadding="0" cellspacing="0">
            <tr>
              <td width="4%" height="35" align="center">
              	<%=pageString%>
              </td>
            </tr>
          </table>
        </td>
      </tr>
    </table>
 


      <input type="hidden" name="menu_id" id="menu_id" value="<%=menu_id %>" />
	  <input type="hidden" name="listsize" id="listsize" value="<%=listsize %>" />
	  <input type="hidden" name="bpm_id" id="bpm_id" value="" />

   </form>
	<form action="/templets/html/order/order_confirm.jsp" name="payment" method="post" target="_blank">
		<input type="hidden" name="trade_no" id="trade_no" value=""/>
		<input type="hidden" name="price" id="price" value=""/>
		<input type="hidden" name="subject" id="subject" value=""/>
		<input type="hidden" name="body" id="body" value=""/>
		<input type="hidden" name="cust_id" id="cust_id" value=""/>
		<input type="hidden" name="all_total_amount" id="all_total_amount" value=""/> 
		<input type="hidden" name="logistics_fee" id="logistics_fee" value=""/>
		<input type="hidden" name="logistics_type" id="logistics_type" value=""/>
	</form>
	<form action="/program/jsalipay/dbpay.jsp" name="paymentdb" method="post" target="_blank">
		<input type="hidden" name="dbout_trade_no" id="dbout_trade_no" value=""/>
		<input type="hidden" name="dbprice" id="dbprice" value=""/>
		<input type="hidden" name="dbsubject" id="dbsubject" value=""/>
		<input type="hidden" name="dbbody" id="dbbody" value=""/>
		<input type="hidden" name="dbcust_id" id="dbcust_id" value=""/>
		<input type="hidden" name="dblogistics_fee" id="dblogistics_fee" value=""/>
		<input type="hidden" name="dblogistics_type" id="dblogistics_type" value=""/>
	</form>
  </div>
  <script type="text/javascript">
	function pay(order_no,prices,logistics_fee,logistics_type,i,cust_id){
		var str = "";
		$(".goods_name"+i).each(function(index){
			str = str + $(this).html()+"|";
		});
		$("#body").val(str);
		$("#trade_no").val(order_no);
		$("#all_total_amount").val(prices);
		$("#price").val(prices);
		$("#subject").val(str);
		$("#cust_id").val(cust_id);
		document.payment.submit();
		
	}
	function paydb(order_no,prices,logistics_fee,logistics_type,i,cust_id){
		var str = "";
		$(".goods_name"+i).each(function(index){
			str = str + $(this).html()+"|";
		});
		$("#dbbody").val(str);
		$("#dbout_trade_no").val(order_no);
		$("#dbprice").val(prices);
		$("#dbsubject").val(str);
		$("#dbcust_id").val(cust_id);
		$("#dblogistics_fee").val(logistics_fee);
		$("#dblogistics_type").val(logistics_type);
		document.paymentdb.submit();
		
	}
  </script>